package carlos.debares;

import java.util.HashMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {
   	private Context mContext;
    
   	private HashMap<Integer, itemComida> htComida = new HashMap(); //Cambiar el tipo de clave
   	//Cambiar por lista si apetece.
	private HashMap<Integer, itemComida> htComida2 = new HashMap();
	private HashMap<Integer, itemComida> htComida3 = new HashMap();
   	
   	private Integer[] mThumbIds = {
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    		  R.drawable.amonite,
    };
   	
    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return mThumbIds[position];
    }
    
  

    // create a new ImageView for each item referenced by the Adapter
    public View getView_old(int position, View convertView, ViewGroup parent) {
        //no es ImageView, es una View propia nuestra
    	ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(5, 5, 5, 5);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
    	View v;
		if(convertView==null){
			//LayoutInflater li = getLayoutInflater();
			LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = li.inflate(R.layout.item_comida, null);
		}
		else
		{
			v = convertView;
		}
		TextView tv = (TextView)v.findViewById(R.id.icon_text);
		tv.setText("Comida:  "+htComida.get(position).getComida());
		ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
		iv.setImageResource(mThumbIds[position]);
		return v;

    }
    
    public void initTable()
    {
    	itemComida item = new itemComida("Amonite0", R.drawable.amonite);
 	    htComida.put(0,item);
 	    item = new itemComida("Amonite1", R.drawable.amonite);
	    htComida.put(1,item);
	    item = new itemComida("Amonite2", R.drawable.amonite);
 	    htComida.put(2,item);
 	    item = new itemComida("Amonite3", R.drawable.amonite);
	    htComida.put(3,item);
	    item = new itemComida("Amonite4", R.drawable.amonite);
 	    htComida.put(4,item);
 	    item = new itemComida("Amonite5", R.drawable.amonite);
	    htComida.put(5,item);
	    item = new itemComida("Amonite6", R.drawable.amonite);
 	    htComida.put(6,item);
 	    item = new itemComida("Amonite7", R.drawable.amonite);
	    htComida.put(7,item);
	    item = new itemComida("Amonite8", R.drawable.amonite);
 	    htComida.put(8,item);
 	   
 	    
    }
    
//    public void initTable()
//    {
//    	itemComida item = new itemComida("Amonite0", R.drawable.amonite);
// 	    htComida.put(0,item);
// 	    item = new itemComida("Amonite1", R.drawable.amonite);
//	    htComida.put(1,item);
//	    item = new itemComida("Amonite2", R.drawable.amonite);
// 	    htComida.put(2,item);
// 	    
//    }
    
    //metodo asqueroso para intentar cargar otro gridview
    
    
    public HashMap returnTable()
    {
    	return htComida;
    }
    

    
}
